#include "wuInvisible.h"

wuInvisible::wuInvisible()
{

}

wuInvisible::~wuInvisible()
{
}

void wuInvisible::captureInvisible(ofImage *currImg, ofImage *bgImg)
{
        color.setFromPixels(currImg->getPixels(), vw,vh);
        gray = color;
        bgColor.setFromPixels(bgImg->getPixels(), vw,vh);
        bgGrayImg = bgColor;

            // take the abs value of the difference between background and incoming and then threshold:
        grayDiff.absDiff(gray, bgGrayImg);
        grayDiff.threshold(threshold);

//        grayDiff.blur(0);
        contour.blobs.clear();
        contour.findContours(grayDiff, minBlobSize, maxBlobSize, maxBlobs, false);	// find holes

        for (int i = 0; i < contour.nBlobs; i++)
        {
            ofRectangle rect;

            rect.x = contour.blobs[i].boundingRect.x;
            rect.y = contour.blobs[i].boundingRect.y;
            rect.width = contour.blobs[i].boundingRect.width;
            rect.height = contour.blobs[i].boundingRect.height;

            wuImagePlus _skinBg;
            _skinBg.crop_no_edge(bgColor.getPixels(), grayDiff.getPixels(), vw, vh, rect);
            wuSkin skin;
            skin.setSkin(&_skinBg, rect);
            skinsInvisible.push_back(skin);
        }
}

void wuInvisible::drawInvisible(bool bDrawlines, int offX)
{
    for(int i=0; i< skinsInvisible.size(); i++)
        skinsInvisible[i].draw(bDrawlines, offX);
}

void wuInvisible::clear()
{
    wuBaseManager::clear();
    skinsInvisible.clear();
}

